//#pragma code
/******************************************************************************
 Project:    Buzzer
 Modul:      buzzer_unit.c
 Descr:      Buzzer Unit

 Date:       18.10.11
 Autor:      rk
 Notes:      -
 ******************************************************************************/

#include "buzzer_unit.h"
#include "buzzer_game.h"
#include "display.h"

volatile BUZZER_UNIT /*idata*/BuzzerUnit[MAX_BUZZERS]; //

/**
 *  Initialize all Buzzers
 *
 *  Sets Ids, State, Time and Displaymode
 *
 * @param uiGameId provide GameId
 */
void BUZZER_UNIT_vIni(ui uiGameId)
{
   for (int i = 0; i < MAX_BUZZERS; i++)
   {
      BuzzerUnit[i].uiBuzzerId = i;
      BuzzerUnit[i].ucBuzzerState = 0;
      BuzzerUnit[i].ulEndTime = 0.0;
      BuzzerUnit[i].ulStartTime = 0.0;

      //BUZZER_UNIT_vSetDisplayMode(DISPLAY_READY, BuzzerUnit[i].uiBuzzerId);
   }
}

/**
 * Sets specific game settings for all Buzzer Units
 *
 * @see GAME_DATA.uiGameId
 *
 * @param uiGameId provide GameId.
 */
void BUZZER_UNIT_vSetGame(ui uiGameId)
{

   for (int i = 0; i < MAX_BUZZERS; i++)
   {

      switch (uiGameId)
      {
         case KO_RUNDE:
         {
            BuzzerUnit[i].ulStartTime = 0.0; //
            BuzzerUnit[i].ulEndTime = 0.0; //
            break;
         }
         case SPERRE:
         {
            BuzzerUnit[i].ulStartTime = 0.0; //
            BuzzerUnit[i].ulEndTime = 0.0; //
            break;
         }
         case SPERRE_REIHENFOLGE:
         {
            BuzzerUnit[i].ulStartTime = 0.0; //
            BuzzerUnit[i].ulEndTime = 0.0; //
            break;
         }
         case WETTRENNEN:
         {
            BuzzerUnit[i].ulStartTime = 0.0; //
            BuzzerUnit[i].ulEndTime = 0.0; //
            break;
         }
         case ABSTIMMUNG:
         {
            BuzzerUnit[i].ulStartTime = 0.0; //
            BuzzerUnit[i].ulEndTime = 0.0; //
            break;
         }
      }

   }
}

/**
 *
 * @param uiDisplayMode Provide DisplayMode
 */
void BUZZER_UNIT_vSetDisplayMode(ui uiDisplayMode, ui uiBuzzerId)
{
	BuzzerUnit[uiBuzzerId].uiDisplayMode = uiDisplayMode;
	DISPLAY_vSetBuzzerDisplayMode(uiDisplayMode, uiBuzzerId);
}

/**
 *
 * @param uiDisplayMode Provide DisplayMode
 */
void BUZZER_UNIT_vSetDisplayModes(ui uiDisplayMode)
{
   for (int i = 0; i < MAX_BUZZERS; i++)
   {
	   BUZZER_UNIT_vSetDisplayMode(uiDisplayMode, i);
   }
}
